home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-03-26 | 53.8 KB | 2,086 lines |
- ---- Cut Here and feed the following to sh ----
- #!/bin/sh
- # This is a shell archive (shar 3.47)
- # made 03/26/1993 20:19 UTC by turtle@hercules
- # Source directory /usr/local/src/public_domain/tools/xvgopher
- #
- # existing files will NOT be overwritten unless -c is specified
- #
- # This shar contains:
- # length mode name
- # ------ ---------- ------------------------------------------
- # 6152 -rw-rw-r-- README
- # 1084 -rw-rw-r-- COPYRIGHT
- # 199 -rw-rw-r-- BUGS
- # 169 -rw-rw-r-- TODO
- # 3684 -rw-r--r-- Makefile
- # 2170 -rw-rw-r-- xvgopher.man
- # 8558 -rw-r--r-- Connection.cc
- # 5530 -rw-rw-r-- GWAbout.cc
- # 498 -rw-r--r-- GWBinary.cc
- # 8907 -rw-rw-r-- GWBookmarks.cc
- # 9592 -rw-rw-r-- GWDirectory.cc
- # 7644 -rw-r--r-- GWDownload.cc
- # 5861 -rw-rw-r-- GWFile.cc
- # 2602 -rw-rw-r-- GWGopher.cc
- # 472 -rw-r--r-- GWImage.cc
- # 2924 -rw-r--r-- GWIndex.cc
- # 1679 -rw-r--r-- GWInfo.cc
- # 8870 -rw-rw-r-- GWList.cc
- # 4701 -rw-r--r-- GWPref.cc
- # 469 -rw-r--r-- GWSound.cc
- # 1331 -rw-r--r-- GWTelnet.cc
- # 7751 -rw-rw-r-- GWindow.cc
- # 8621 -rw-rw-r-- Gopher.cc
- # 1821 -rw-r--r-- List.cc
- # 5632 -rw-rw-r-- Preferences.cc
- # 2479 -rw-r--r-- Response.cc
- # 3627 -rw-r--r-- cursor.cc
- # 2754 -rw-rw-r-- icons.cc
- # 996 -rw-rw-r-- main.cc
- # 486 -rw-r--r-- Config.h
- # 1949 -rw-r--r-- Connection.h
- # 620 -rw-r--r-- GWAbout.h
- # 417 -rw-r--r-- GWBinary.h
- # 1124 -rw-r--r-- GWBookmarks.h
- # 1210 -rw-rw-r-- GWDirectory.h
- # 966 -rw-r--r-- GWDownload.h
- # 481 -rw-r--r-- GWFile.h
- # 646 -rw-rw-r-- GWGopher.h
- # 411 -rw-r--r-- GWImage.h
- # 503 -rw-r--r-- GWIndex.h
- # 569 -rw-r--r-- GWInfo.h
- # 1107 -rw-rw-r-- GWList.h
- # 860 -rw-r--r-- GWPref.h
- # 411 -rw-r--r-- GWSound.h
- # 458 -rw-r--r-- GWTelnet.h
- # 1931 -rw-rw-r-- GWindow.h
- # 1608 -rw-r--r-- Gopher.h
- # 771 -rw-r--r-- List.h
- # 1892 -rw-r--r-- Object.h
- # 1347 -rw-r--r-- Preferences.h
- # 2963 -rw-r--r-- Response.h
- # 1684 -rw-r--r-- String.h
- # 241 -rw-r--r-- cursor.h
- # 248 -rw-r--r-- icons.h
- # 2810 -rw-rw-r-- xvgopher.h
- # 222 -rw-r--r-- icons/bin
- # 222 -rw-r--r-- icons/cso
- # 222 -rw-r--r-- icons/dir
- # 222 -rw-r--r-- icons/doc
- # 222 -rw-r--r-- icons/dos
- # 222 -rw-r--r-- icons/error
- # 2190 -rw-r--r-- icons/gopher.icon
- # 2190 -rw-r--r-- icons/gopher.icon.mask
- # 2190 -rw-r--r-- icons/gopher1
- # 2190 -rw-r--r-- icons/gopher1.mask
- # 2190 -rw-r--r-- icons/gopher2
- # 2190 -rw-r--r-- icons/gopher2.mask
- # 222 -rw-r--r-- icons/idx
- # 222 -rw-r--r-- icons/image
- # 222 -rw-r--r-- icons/info
- # 222 -rw-r--r-- icons/info_dragging
- # 222 -rw-r--r-- icons/mac
- # 222 -rw-r--r-- icons/sound
- # 222 -rw-r--r-- icons/tel
- # 222 -rw-r--r-- icons/unknown
- # 222 -rw-r--r-- icons/uu
- #
- # ============= README ==============
- if test -f 'README' -a X"$1" != X"-c"; then
- echo 'x - skipping README (File already exists)'
- else
- echo 'x - extracting README (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'README' &&
- README
- X
- This is a beta release of xvgopher -- an XView based gopher client.
- X
- Gopher is a distributed information browsing/retrieval system used at
- many universities and other institutions to make information and
- services available in a user friendly and consistent manner.
- X
- NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
- This is a beta release! This means that I am still very actively working
- on xvgopher, but I got many requests to make it available ASAP.
- Please report any problems you find as soon as possible so that I can
- incorporate the fixes in the first major release.
- The latest release will always be available. There are two ways of
- accessing it:
- X
- X anonymous ftp to gopher.sdsu.edu in /pub/xvgopher
- X gopher to gopher.sdsu.edu: Software Distribution/UNIX/XvGopher
- X
- X
- HISTORY OF XVGOPHER
- We started out wanting something similar to TurboGopher (a Macintosh
- gopher client. Really nice!!) for MS-Windows. There are several good
- pc gopher clients available, but the ones I checked out either didn't
- run as a MS-Windows application, weren't public domain, or required
- some non- public domain networking software. (We are on an extreemly
- low budget...) So, we decided to write one...
- X
- Well, this would have been great, but I refused to write any MS-Windows
- applications on my 20 MHz 386! So, while waiting for a better PC, I
- decided I might as well write a prototype using XView.
- X
- I should point out that there is a pretty nice X11 gopher client
- available called xgopher. However, it boils down to a fancy window
- around something similar to the text based gopher client. (This is
- greatly exaggerated, of course!) We did use the gopher icon that
- xgopher uses. It is pretty cute (and none of us are good artists.)
- X
- The prototype I started writing turned out to be quite usable and we
- started using it instead of the text based client. It is not a
- prototype anymore; it is now a full gopher client.
- X
- I wrote all of xvgopher in C++ because that is the language I am most
- comfortable with. I used the Sniff C++ development system to write
- all the code and I used Sun's DevGuide to figure out sizes of windows and
- locations of buttons. I did not use DevGuide for the code generation
- for several reasons: 1) Not everyone has DevGuide which makes it hard
- to distribute the source code. 2) The C++ code generator that comes with
- DevGuide doesn't really do anything in an object oriented way. It would
- make the code horrible! (Actually, XView is not very easy to integrate
- in an object oriented program because of all the callbacks...)
- X
- X
- SYSTEM REQUIREMENTS
- xvgopher is written in C++. This may scare some people, but not to
- worry. If you do not have a C++ compiler, just get gcc 2.3.3 and
- libg++. xvgopher will compile with those just fine. So far it has
- been tested on various suns running SunOS 4.1.X and on an HP 750.
- The code does not use any C++ features not available in cfront 2.1. So
- if your C++ compiler does not support templates.... neither does
- ours!!! (We only just got SunPRO's C++ 3.0 compiler. Thanks for the
- great 15 minute license linger time, SunPRO!!!!! :-( Stuff like that
- doesn't work in a University environment! (ANDREW!!! GET OFF THAT
- SOAP BOX!!!)) xvgopher also requires that you have XView3 installed on
- your system. If you have Sun's Openwin 3.0, that's fine too, although
- you will have to have the 'Openwin Programmers' section installed. The
- only other requirement is that you have to have some network so you can
- talk to a gopher server.
- X
- X
- CONFIGURING
- Configuring xvgopher is pretty straight forward. Just edit
- 'xvgopher.h' and change the defines above the section that says to not
- edit anything below it. (Did I make you read that sentence twice??
- :-)) Then edit the Makefile and change the macros to your liking.
- X
- X
- COMPILING & LINKING
- Type 'make depend'
- Type 'make'
- X
- X
- INSTALLING
- type 'make install'
- It will install the xvgopher executable and the man page.
- X
- X
- USER CONFIGURATION
- The first time xvgopher is run by a user, it creates ~/.xvgopher-defaults.
- This file contains all the currently configurable items. The easiest
- is to change those parameters using the Preferences popup, but they can
- also be edited by hand. Xvgopher uses the X11 resource database
- routines to read the items, so the format of the file should be
- familiar. When bookmarks are created, a file called ~/.xvgopher-bm
- will be created which contains a list of bookmarks. The bookmarks are
- stored in the same way they information was sent from a gopher server
- to xvgopher. If you are not familiar with the gopher protocol, don't
- worry about it. If you ARE familiar with the gopher protocol, don't
- worry about it too much.
- X
- CREDITS
- (These really should be slowly scrolling by while appropriate music
- is playing, but you have to wait for version 427 for that feature...)
- Thanks to all the people who have done testing and given me feedback
- on the design and implementation of xvgopher.
- Here are some names:
- X
- Mark Boyns (SDSU) -- testing & UI layout & icons
- John Denune (SDSU) -- testing
- Mike Halderman (NOSC) -- testing
- Paul Lindner (UMN) -- gopher icon
- X
- X
- BUGS, COMMENTS, GRIPES, MONEY, LOVE
- If you have any of the above directed at me, I'd like to hear about
- it! I would especially welcome any bug reports (and possible fixes)
- and also comments. I like getting email!
- Basically, if you like it, let me know why.
- If you dislike it, let me know why.
- If you had problems, let me know why.
- If you have not tried xvgopher but still have comments about it, let me
- know why.
- If you don't like me, let me know why.
- If you think this is getting silly, let me know why.
- If you are still reading this list of questions, you owe me beer!!!
- X
- X
- WHERE IS ANDREW??
- Well, I am reachable by email at turtle@sciences.sdsu.edu
- X
- Happy gophering to y'all! C++'ya in gopherspace.
- X
- X
- --Andrew
- ____________________________________________________________________________
- Andrew "Race Turtle" Scherpbier, SysMgr
- College of Sciences
- San Diego State University
- EMAIL: turtle@sciences.sdsu.edu
- VOICE: (619) 594-5026
- FAX: (619) 594-6381
- ____________________________________________________________________________
- SHAR_EOF
- chmod 0664 README ||
- echo 'restore of README failed'
- Wc_c="`wc -c < 'README'`"
- test 6152 -eq "$Wc_c" ||
- echo 'README: original size 6152, current size' "$Wc_c"
- fi
- # ============= COPYRIGHT ==============
- if test -f 'COPYRIGHT' -a X"$1" != X"-c"; then
- echo 'x - skipping COPYRIGHT (File already exists)'
- else
- echo 'x - extracting COPYRIGHT (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'COPYRIGHT' &&
- This software is Copyright 1993, San Diego State University -- College
- of Sciences
- X
- ------------------------------------------------------------------------
- WARRANTY DISCLAIMER
- X
- This software was created by Andrew Scherpbier at San Diego State
- University and is distributed free of charge. It is placed in the
- public domain and permission is granted to anyone to use, duplicate,
- modify and redistribute it provided that this notice is attached and
- that the modified sources are sent back to San Diego State University.
- X
- San Diego State University and Andrew Scherpbier provide absolutely NO
- WARRANTY OF ANY KIND with respect to this software. The entire risk as
- to the quality and performance of this software is with the user. IN
- NO EVENT WILL SAN DIEGO STATE UNIVERSITY OR ANDREW SCHERPBIER BE LIABLE
- TO ANYONE FOR ANY DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE,
- INCLUDING, WITHOUT LIMITATION, DAMAGES RESULTING FROM LOST DATA OR LOST
- PROFITS, OR FOR ANY SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES.
- ------------------------------------------------------------------------
- SHAR_EOF
- chmod 0664 COPYRIGHT ||
- echo 'restore of COPYRIGHT failed'
- Wc_c="`wc -c < 'COPYRIGHT'`"
- test 1084 -eq "$Wc_c" ||
- echo 'COPYRIGHT: original size 1084, current size' "$Wc_c"
- fi
- # ============= BUGS ==============
- if test -f 'BUGS' -a X"$1" != X"-c"; then
- echo 'x - skipping BUGS (File already exists)'
- else
- echo 'x - extracting BUGS (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'BUGS' &&
- Known bugs.
- X
- Version 1.0 (March, 1993)
- X
- 1 'Another gopher...' pops up two windows for some reason.
- 2 Sometimes, when double clicking on multiple items, some of the
- X windows will never become unbusy.
- SHAR_EOF
- chmod 0664 BUGS ||
- echo 'restore of BUGS failed'
- Wc_c="`wc -c < 'BUGS'`"
- test 199 -eq "$Wc_c" ||
- echo 'BUGS: original size 199, current size' "$Wc_c"
- fi
- # ============= TODO ==============
- if test -f 'TODO' -a X"$1" != X"-c"; then
- echo 'x - skipping TODO (File already exists)'
- else
- echo 'x - extracting TODO (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'TODO' &&
- Things I still need to add to xvgopher.
- X
- + Timeouts for network activities
- X
- + Support for CSO phonebook searches
- X
- + More flexible configuration
- X
- + Hierarchal bookmarks
- X
- SHAR_EOF
- chmod 0664 TODO ||
- echo 'restore of TODO failed'
- Wc_c="`wc -c < 'TODO'`"
- test 169 -eq "$Wc_c" ||
- echo 'TODO: original size 169, current size' "$Wc_c"
- fi
- # ============= Makefile ==============
- if test -f 'Makefile' -a X"$1" != X"-c"; then
- echo 'x - skipping Makefile (File already exists)'
- else
- echo 'x - extracting Makefile (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'Makefile' &&
- #
- # Makefile for xvgopher.
- #
- # (c) Copyright 1993, San Diego State University -- College of Sciences
- # (See the COPYRIGHT file for more Copyright information)
- #
- # This makefile will work on standard Sun4 systems running SunOS 4.1.X
- # and which have the Sun C++ compiler installed in /usr/lang
- # If your configuration differs, you will have to modify the rest of this
- # file.
- #
- # The directory the executable should be installed in
- BINDIR = /usr/local/bin
- X
- #
- # The directory where the man page should go
- MANDIR = /usr/local/man
- X
- #
- # The section to use for the man page.
- MANSECT = l
- X
- #
- # Compiler to use. It has been tested with Sun C++ 2.0, g++ 2.3.3, and
- # Sun C++ 3.0
- #CCC = CC
- #CCC = g++ -fno-strict-prototypes -w
- CCC = /usr/local/lang/CC
- X
- #
- # Flags for the compiler. We use openwin for our X development, but
- # the standard x11r5/xview3 will work just fine.
- #
- CCFLAGS = -I$(OPENWINHOME)/include -O
- X
- #
- # I specified the openwin libraries specifically to get around some
- # problems with people not mounting our x11r5 tree. Using this overrides
- # the LD_LIBRARY_PATH environment and makes the shared version work on
- # all machines with openwin3
- #
- LDFLAGS = -g -L/usr/openwin/lib
- X
- #
- # The makedepend looks in the 'standard' places for system include files.
- # Well, Sun decided they weren't going to use the 'standard' places for
- # their compilers, so we have to specifiy the actual path... (Bogus!!!)
- #
- SYS_INCLUDES = -I/usr/lang/SC1.0/include/CC
- #SYS_INCLUDES = -I/usr/local/gnu/lib/g++-include -I/usr/local/gnu/lib/gcc-lib/sparc-sun-sunos4.1.2/2.3.3/include
- X
- #
- # Strangely enough xvgopher uses xview!!!
- #
- LIBS = -lxview -lolgx -lX11
- X
- #
- # All the files which will end up with an object file. (Can't just say
- # all source files, because in C++ the headers can contain all kinds of
- # source as well...)
- #
- SRCS = \
- X Connection.cc \
- X GWAbout.cc \
- X GWBinary.cc \
- X GWBookmarks.cc \
- X GWDirectory.cc \
- X GWDownload.cc \
- X GWFile.cc \
- X GWGopher.cc \
- X GWImage.cc \
- X GWIndex.cc \
- X GWInfo.cc \
- X GWList.cc \
- X GWPref.cc \
- X GWSound.cc \
- X GWTelnet.cc \
- X GWindow.cc \
- X Gopher.cc \
- X List.cc \
- X Preferences.cc \
- X Response.cc \
- X cursor.cc \
- X icons.cc \
- X main.cc
- X
- #
- # I am lazy. I hate typing in lists into makefiles! I think the word
- # replacement macro in makefiles is the best thing since sliced cheese!
- #
- OBJS = $(SRCS:%.cc=%.o)
- X
- #
- # The list of files to put in the shar archive
- #
- SHARFILES = \
- X README \
- X COPYRIGHT \
- X BUGS \
- X TODO \
- X Makefile \
- X xvgopher.man \
- X $(SRCS) \
- X *.h \
- X icons/*
- X
- TARGET = xvgopher
- X
- all: $(TARGET)
- X
- $(TARGET): $(OBJS)
- X $(CCC) $(LDFLAGS) -o $(TARGET) $(OBJS) $(LIBS)
- X
- static: $(OBJS)
- X $(CCC) $(LDFLAGS) -o $(TARGET).static $(OBJS) -Bstatic $(LIBS)
- X
- clean:
- X rm -f $(OBJS) $(TARGET) *.bak *.BAK
- X
- #
- # The installation of the program.
- #
- install: $(TARGET)
- X install -s $(TARGET) $(BINDIR)
- X install xvgopher.man $(MANDIR)/man$(MANSECT)/xvgopher.$(MANSECT)
- X
- #
- # I use makedepend. If you don't have it, get it!
- #
- depend:
- X makedepend -- $(CCFLAGS) $(SYS_INCLUDES) -- $(SRCS)
- X
- #
- # Create a shar file suitable for posting
- #
- shar:
- X shar -c -o xvgopher.shar -l55 $(SHARFILES)
- X
- #
- # Create some tar files suitable for ftping.
- #
- tar:
- X gnutar czvf xvgopher.tar.z $(SHARFILES)
- X gnutar cZvf xvgopher.tar.Z $(SHARFILES)
- X
- zeus:
- X gnutar czvf /tmp/xvg.tar.Z *.cc *.h Makefile icons/*
- X rcp /tmp/xvg.tar.Z zeus:
- X rm /tmp/xvg.tar.Z
- X
- kiwi:
- X gnutar czvf /tmp/xvg.tar.Z *.cc *.h Makefile icons/*
- X rcp /tmp/xvg.tar.Z kiwi:
- X rm /tmp/xvg.tar.Z
- X
- rohan:
- X gnutar czvf /tmp/xvg.tar.Z *.cc *.h Makefile icons/*
- X rcp /tmp/xvg.tar.Z rohan:
- X rm /tmp/xvg.tar.Z
- X
- saturn:
- X gnutar czvf /tmp/xvg.tar.Z *.cc *.h Makefile icons/*
- X rcp /tmp/xvg.tar.Z saturn:
- X rm /tmp/xvg.tar.Z
- SHAR_EOF
- chmod 0644 Makefile ||
- echo 'restore of Makefile failed'
- Wc_c="`wc -c < 'Makefile'`"
- test 3684 -eq "$Wc_c" ||
- echo 'Makefile: original size 3684, current size' "$Wc_c"
- fi
- # ============= xvgopher.man ==============
- if test -f 'xvgopher.man' -a X"$1" != X"-c"; then
- echo 'x - skipping xvgopher.man (File already exists)'
- else
- echo 'x - extracting xvgopher.man (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'xvgopher.man' &&
- .TH xvgopher l "25 March 1993"
- .SH NAME
- xvgopher \- XView gopher client program
- .SH SYNOPSIS
- xvgopher [
- .I servername
- [
- .I port#
- ] ]
- .SH DESCRIPTION
- .B Xvgopher
- is a user friendly gopher client.
- When started,
- .B xvgopher
- will show the root directory of the gopher server
- which was selected when it was compiled.
- The type of each item in the list is indicated my a small icon.
- The meaning of the icons should be pretty clear, but if you can draw
- better icons, send them to me!!!
- To activate an item, just double click on it.
- .LP
- The Gopher menu in the main window contains several useful items:
- .TP 8
- \(bu Bookmarks...
- This will create a window showing your your bookmarks.
- .TP 8
- \(bu Another Gopher...
- This will allow you to contact another gopher server.
- You can specify both the server name and the port number.
- .TP 8
- \(bu Preferences...
- This will create a window which allows you to modify things like the
- commands to execute for certain things.
- .TP 8
- \(bu About...
- This will create a window showing who created
- .B Xvgopher
- .SH OPTIONS
- By default,
- .B xvgopher
- will contact whatever server it was compiled with.
- If a
- .I servername
- is specified,
- .B xvgopher
- will try to contact that server at port 70.
- You can modify the port number of the remote server by also specifying
- .I port#
- .SH FILES
- .TP 25
- .B $HOME/.xvgopher-defaults
- defaults in .Xdefaults format
- .TP 25
- .B $HOME/.xvgopher-bm
- bookmarks as the gopher server would want them
- .SH SEE ALSO
- gopher(l), xgopher(l)
- .SH NOTES
- .B Xvgopher
- does not currently support the CSO phone book servers.
- .SH BUGS
- There are no bugs! Maybe some undocumented features, but no bugs... :-)
- .LP
- In the unlikely event that you do find a problem or if you have suggestions
- on how to improve
- .B xvgopher,
- send mail to
- .B xvgopher@gopher.sdsu.edu
- .SH CREDITS
- .TP 8
- Programmer:
- .B "Andrew Scherpbier"
- .TP 8
- Icons:
- .B "Paul Lindner"
- did the original gopher icon.
- .B "Mark Boyns"
- did all the small icons and made the gopher chew.
- .TP 8
- Layout:
- .B "Andrew Scherpbier"
- and
- .B "Mark Boyns"
- with input from many other testers.
- .TP 8
- Testing:
- .B "Mark Boyns,"
- .B "John Denune,"
- .B "Bob Cademy,"
- .B "Mike Halderman,"
- and many other guinea pigs.
- SHAR_EOF
- chmod 0664 xvgopher.man ||
- echo 'restore of xvgopher.man failed'
- Wc_c="`wc -c < 'xvgopher.man'`"
- test 2170 -eq "$Wc_c" ||
- echo 'xvgopher.man: original size 2170, current size' "$Wc_c"
- fi
- # ============= Connection.cc ==============
- if test -f 'Connection.cc' -a X"$1" != X"-c"; then
- echo 'x - skipping Connection.cc (File already exists)'
- else
- echo 'x - extracting Connection.cc (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'Connection.cc' &&
- //
- // Connection.cc
- //
- // (c) Copyright 1993, San Diego State University -- College of Sciences
- // (See the COPYRIGHT file for more Copyright information)
- //
- // Implementation of the Connection class
- //
- X
- #include "Connection.h"
- #include <errno.h>
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <sys/ioctl.h>
- #include <unistd.h>
- X
- X
- Connection::Connection()
- {
- X sock = -1;
- X pos = pos_max = 0;
- }
- X
- X
- //*************************************************************************
- // Connection::Connection(int socket)
- // PURPOSE:
- // Create a connection from just a socket.
- // PARAMETERS:
- // int socket: obvious!!!!
- //
- Connection::Connection(int socket)
- {
- X sock = socket;
- X
- X int length = sizeof(server);
- X if (getpeername(socket, (struct sockaddr *)&server, &length) < 0)
- X {
- X perror("getpeername");
- X }
- X pos = pos_max = 0;
- }
- X
- X
- Connection::~Connection()
- {
- X this->close();
- }
- X
- X
- int Connection::open(int priv)
- {
- X if (priv)
- X {
- X int aport = IPPORT_RESERVED - 1;
- X
- X sock = rresvport(&aport);
- X }
- X else
- X sock = socket(AF_INET, SOCK_STREAM, 0);
- X
- X if (sock == NOTOK)
- X return NOTOK;
- X
- X int on = 1;
- X setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof(on));
- X server.sin_family = AF_INET;
- X
- X pos = pos_max = 0;
- X return OK;
- }
- X
- X
- int Connection::close()
- {
- X if (sock >= 0)
- X {
- X int ret = ::close(sock);
- X sock = -1;
- X return ret;
- X }
- X return NOTOK;
- }
- X
- X
- int Connection::assign_port(int port)
- {
- X server.sin_port = htons(port);
- X return OK;
- }
- X
- X
- int Connection::assign_port(char *service)
- {
- X struct servent *sp;
- X
- X sp = getservbyname(service, "tcp");
- X if (sp == NULL)
- X {
- X return NOTOK;
- X }
- X server.sin_port = sp->s_port;
- X return OK;
- }
- X
- int Connection::assign_server(dword addr)
- {
- X server.sin_addr.s_addr = addr;
- X return OK;
- }
- X
- int Connection::assign_server(char *name)
- {
- X struct hostent *hp;
- X
- X hp = gethostbyname(name);
- X if (hp == NULL)
- X {
- X return NOTOK;
- X }
- X memcpy((char *)&server.sin_addr, (char *)hp->h_addr, hp->h_length);
- X return OK;
- }
- X
- X
- int Connection::connect()
- {
- X if (::connect(sock, (struct sockaddr *)&server, sizeof(server)) == NOTOK)
- X {
- X return NOTOK;
- X }
- X return OK;
- }
- X
- X
- int Connection::bind()
- {
- X if (::bind(sock, (struct sockaddr *)&server, sizeof(server)) == NOTOK)
- X {
- X return NOTOK;
- X }
- X return OK;
- }
- X
- X
- int Connection::get_port()
- {
- X int length;
- X
- X if (getsockname(sock, (struct sockaddr *)&server, &length) == NOTOK)
- X {
- X return NOTOK;
- X }
- X return ntohs(server.sin_port);
- }
- X
- X
- int Connection::listen(int n)
- {
- X return ::listen(sock, n);
- }
- X
- X
- Connection *Connection::accept(int priv)
- {
- X int newsock;
- X
- X while (TRUE)
- X {
- X newsock = ::accept(sock, (struct sockaddr *)0, (int *)0);
- X if (newsock == NOTOK && errno == EINTR)
- X continue;
- X break;
- X }
- X if (newsock == NOTOK)
- X return (Connection *)0;
- X
- X Connection *newconnect = new Connection;
- X newconnect->sock = newsock;
- X
- X int length = sizeof(newconnect->server);
- X getpeername(newsock, (struct sockaddr *)&newconnect->server, &length);
- X
- X if (priv && newconnect->server.sin_port >= IPPORT_RESERVED)
- X {
- X delete newconnect;
- X return (Connection *)0;
- X }
- X
- X return newconnect;
- }
- X
- X
- //*************************************************************************
- // Connection *Connection::accept_privileged()
- // PURPOSE:
- // Accept in incoming connection but only if it is from a
- // privileged port
- //
- Connection * Connection::accept_privileged()
- {
- X return accept(1);
- }
- X
- X
- //*************************************************************************
- // METHOD int Connection::write(char *buffer, int length)
- // PURPOSE:
- // Write <nbytes> bytes from <buffer> to file sock. This will
- // take care of problems where write will return without having
- // written everything in the buffer.
- // PARAMETERS:
- // char *buffer: The buffer to write.
- // int nbytes: The number of bytes to write from <buffer>.
- // RETURN VALUE:
- // Returns number of bytes actually written. If there was an
- // error it returns -1.
- // SIDE EFFECTS:
- // None
- // ASSUMPTIONS:
- // None
- // FUNCTIONS USED:
- // write()
- // ALGORYTHM:
- // Stevens p. 279
- //
- int Connection::write(char *buffer, int length)
- {
- X int nleft, nwritten;
- X
- X nleft = length;
- X while (nleft > 0)
- X {
- X nwritten = ::write(sock, buffer, nleft);
- X if (nwritten <= 0)
- X return nwritten;
- X nleft -= nwritten;
- X buffer += nwritten;
- X }
- X return length - nleft;
- }
- X
- X
- //*************************************************************************
- // METHOD int Connection::write(char *buffer)
- // PURPOSE:
- // This is identical to the other write except that the length of the
- // buffer is not passed. The buffer is assumed to be NULL terminated.
- // PARAMETERS:
- // char *buffer: The buffer to write.
- // RETURN VALUE:
- // Returns number of bytes actually written. If there was an
- // error it returns -1.
- //
- int Connection::write(char *buffer)
- {
- X return write(buffer, strlen(buffer));
- }
- X
- X
- //*************************************************************************
- // int Connection::read(char *buffer, int length)
- // PURPOSE:
- // Read <length> bytes from the current TCP connection. We will
- // not return until we have all the data we are waiting for
- // unless there was an error
- // PARAMETERS:
- // char *buffer: Buffer to read the data into
- // int length: The number of bytes to read into the buffer
- // RETURN VALUE:
- // The actual number of bytes read. NOTOK if an error occured.
- // ASSUMPTIONS:
- // The connection has been previously established.
- // FUNCTIONS USED:
- // read()
- // ALGORYTHM:
- // Stevens p. 279
- //
- int Connection::read(char *buffer, int length)
- {
- X int nleft, nread;
- X
- X nleft = length;
- X while (nleft > 0)
- X {
- X nread = ::read(sock, buffer, nleft);
- X if (nread < 0 && errno == EINTR)
- X continue;
- X else if (nread < 0)
- X {
- X perror("read");
- X return nread;
- X }
- X else if (nread == 0)
- X return -1; // End of file/stream
- X
- X nleft -= nread;
- X buffer += nread;
- X }
- X return length - nleft;
- }
- X
- X
- //***************************************************************************
- // char *Connection::read_line(char *buffer, int maxlength)
- // PURPOSE:
- // Read a line of text, terminated by CR and or LF.
- //
- char *Connection::read_line(char *buffer, int maxlength)
- {
- X while (maxlength > 0)
- X {
- X int ch = get_char();
- X if (ch < 0)
- X return (char *) 0;
- X else if (ch == '\r')
- X continue;
- X else if (ch == '\n')
- X break;
- X else
- X {
- X *buffer++ = ch;
- X maxlength--;
- X }
- X }
- X *buffer = '\0';
- X return buffer;
- }
- X
- X
- //*************************************************************************
- // int Connection::read_partial(char *buffer, int maxlength)
- // PURPOSE:
- // Read at most <maxlength> from the current TCP connection.
- // This is equivalent to the workings of the standard read()
- // system call
- // PARAMETERS:
- // char *buffer: Buffer to read the data into
- // int maxlength: Maximum number of bytes to read into the buffer
- // RETURN VALUE:
- // The actual number of bytes read in.
- // ASSUMPTIONS:
- // The connection has been previously established.
- // FUNCTIONS USED:
- // read()
- //
- int Connection::read_partial(char *buffer, int maxlength)
- {
- X return ::read(sock, buffer, maxlength);
- }
- X
- X
- //*************************************************************************
- // int Connection::bytes_available()
- // PURPOSE:
- // Check to see how many bytes can be read from the connection
- // currently
- // RETURN VALUE:
- // The number of bytes available.
- //
- int Connection::bytes_available()
- {
- X int count = -1;
- X
- X ioctl(sock, FIONREAD, (char *) &count);
- X
- X return count;
- }
- X
- X
- //*************************************************************************
- // char * Connection::socket_as_string()
- // PURPOSE:
- // Return the numeric ASCII equivalent of the socket number.
- // This is needed to pass the socket to another program
- //
- char * Connection::socket_as_string()
- {
- X char buffer[20];
- X
- X sprintf(buffer, "%d", sock);
- X return strdup(buffer);
- }
- X
- X
- //*************************************************************************
- // int Connection::get_socket()
- // PURPOSE:
- // Return the current socket number
- //
- int Connection::get_socket()
- {
- X return sock;
- }
- X
- X
- //*************************************************************************
- // int Connection::isopen()
- // PURPOSE:
- // Return true if the connection is open
- //
- int Connection::isopen()
- {
- X return sock >= 0;
- }
- X
- X
- //*************************************************************************
- // int Connection::get_char()
- //
- int Connection::get_char()
- {
- X if (pos >= pos_max)
- X {
- X pos_max = read_partial(buffer, BUFFER_SIZE);
- X pos = 0;
- X if (pos_max <= 0)
- X return -1;
- X }
- X return buffer[pos++];
- }
- X
- X
- SHAR_EOF
- chmod 0644 Connection.cc ||
- echo 'restore of Connection.cc failed'
- Wc_c="`wc -c < 'Connection.cc'`"
- test 8558 -eq "$Wc_c" ||
- echo 'Connection.cc: original size 8558, current size' "$Wc_c"
- fi
- # ============= GWAbout.cc ==============
- if test -f 'GWAbout.cc' -a X"$1" != X"-c"; then
- echo 'x - skipping GWAbout.cc (File already exists)'
- else
- echo 'x - extracting GWAbout.cc (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'GWAbout.cc' &&
- //
- // GWAbout.cc
- //
- // (c) Copyright 1993, San Diego State University -- College of Sciences
- // (See the COPYRIGHT file for more Copyright information)
- //
- // Implementation of the GWAbout class
- //
- #include "GWAbout.h"
- #include "xvgopher.h"
- #include "cursor.h"
- #include <fcntl.h>
- #include <unistd.h>
- X
- #define KEY_TEXT_ITEM 20000
- X
- X
- static int current_icon = 0;
- static Panel_item icon;
- X
- X
- //***************************************************************************
- // GWAbout::GWAbout(Frame par)
- //
- GWAbout::GWAbout(Frame par)
- {
- X parent = par;
- }
- X
- X
- //***************************************************************************
- // int GWAbout::open(Response *)
- // PURPOSE:
- // This will create an about window
- //
- int GWAbout::open(Response *)
- {
- X info = NULL;
- X compute_location(407, 107);
- X frame = (Frame) xv_create(parent, FRAME_CMD,
- X XV_X, next_x,
- X XV_Y, next_y,
- X XV_WIDTH, 465,
- X XV_HEIGHT, 369,
- X FRAME_LABEL, "About XvGopher",
- X FRAME_CMD_PIN_STATE, FRAME_CMD_PIN_OUT,
- X FRAME_SHOW_RESIZE_CORNER, FALSE,
- X XV_SHOW, TRUE,
- X FRAME_SHOW_FOOTER, FALSE,
- X FRAME_DONE_PROC, (void (*)(Frame)) done_proc,
- X XV_KEY_DATA, KEY_GWINDOW, this,
- X NULL);
- X panel = (Panel) xv_get(frame, FRAME_CMD_PANEL);
- X
- X //
- X // Interpose onto the panel so that events will generate a call
- X //
- X notify_interpose_event_func(panel, (Notify_func) panel_events, NOTIFY_SAFE);
- X
- X //
- X // Create all the panel items
- X //
- X icon = (Panel_item) xv_create(panel, PANEL_MESSAGE,
- X XV_X, 24,
- X XV_Y, 12,
- X PANEL_LABEL_IMAGE, get_gopher(0),
- X NULL);
- X xv_create(panel, PANEL_MESSAGE,
- X XV_X, 112,
- X XV_Y, 16,
- X PANEL_LABEL_STRING, "XvGopher",
- X PANEL_LABEL_BOLD, TRUE,
- X NULL);
- X xv_create(panel, PANEL_MESSAGE,
- X XV_X, 112,
- X XV_Y, 39,
- X PANEL_LABEL_STRING, "Version 1.0",
- X PANEL_LABEL_BOLD, TRUE,
- X NULL);
- X xv_create(panel, PANEL_MESSAGE,
- X XV_X, 112,
- X XV_Y, 62,
- X PANEL_LABEL_STRING, "(c) Copyright 1993, San Diego StateUniversity",
- X PANEL_LABEL_BOLD, TRUE,
- X NULL);
- X xv_create(panel, PANEL_MESSAGE,
- X XV_X, 20,
- X XV_Y, 96,
- X PANEL_LABEL_STRING, "XvGopher was written in C++ by Andrew Scherpbier at SDSU.",
- X PANEL_LABEL_BOLD, FALSE,
- X NULL);
- X xv_create(panel, PANEL_MESSAGE,
- X XV_X, 20,
- X XV_Y, 124,
- X PANEL_LABEL_STRING, "Many thanks to the following people for testing, suggestions, and beer:",
- X PANEL_LABEL_BOLD, FALSE,
- X NULL);
- X xv_create(panel, PANEL_MESSAGE,
- X XV_X, 56,
- X XV_Y, 156,
- X PANEL_LABEL_STRING, "Mark Boyns",
- X PANEL_LABEL_BOLD, TRUE,
- X NULL);
- X xv_create(panel, PANEL_MESSAGE,
- X XV_X, 56,
- X XV_Y, 179,
- X PANEL_LABEL_STRING, "John Denune",
- X PANEL_LABEL_BOLD, TRUE,
- X NULL);
- X xv_create(panel, PANEL_MESSAGE,
- X XV_X, 56,
- X XV_Y, 202,
- X PANEL_LABEL_STRING, "Mike Halderman",
- X PANEL_LABEL_BOLD, TRUE,
- X NULL);
- X xv_create(panel, PANEL_MESSAGE,
- X XV_X, 56,
- X XV_Y, 225,
- X PANEL_LABEL_STRING, "Paul Lindner",
- X PANEL_LABEL_BOLD, TRUE,
- X NULL);
- X xv_create(panel, PANEL_MESSAGE,
- X XV_X, 216,
- X XV_Y, 156,
- X PANEL_LABEL_STRING, "Layout, icons, gopher chew, testing",
- X PANEL_LABEL_BOLD, FALSE,
- X NULL);
- X xv_create(panel, PANEL_MESSAGE,
- X XV_X, 216,
- X XV_Y, 179,
- X PANEL_LABEL_STRING, "Testing",
- X PANEL_LABEL_BOLD, FALSE,
- X NULL);
- X xv_create(panel, PANEL_MESSAGE,
- X XV_X, 216,
- X XV_Y, 202,
- X PANEL_LABEL_STRING, "Testing",
- X PANEL_LABEL_BOLD, FALSE,
- X NULL);
- X xv_create(panel, PANEL_MESSAGE,
- X XV_X, 216,
- X XV_Y, 225,
- X PANEL_LABEL_STRING, "Gopher icon",
- X PANEL_LABEL_BOLD, FALSE,
- X NULL);
- X xv_create(panel, PANEL_MESSAGE,
- X XV_X, 20,
- X XV_Y, 260,
- X PANEL_LABEL_STRING, "If you have comments or suggestions, please send E-Mail to:",
- X PANEL_LABEL_BOLD, FALSE,
- X NULL);
- X xv_create(panel, PANEL_MESSAGE,
- X XV_X, 60,
- X XV_Y, 292,
- X PANEL_LABEL_STRING, "xvgopher@gopher.sdsu.edu",
- X PANEL_LABEL_BOLD, TRUE,
- X NULL);
- X xv_create(panel, PANEL_BUTTON,
- X XV_X, 201,
- X XV_Y, 328,
- X PANEL_LABEL_STRING, "Dismiss",
- X PANEL_NOTIFY_PROC, dismiss_proc,
- X NULL);
- X return OK;
- }
- X
- X
- //***************************************************************************
- // void GWAbout::dismiss_proc(Frame frame, Event *)
- // PURPOS:
- // This gets called when the user presses 'q' in a window.
- //
- void GWAbout::dismiss_proc(Frame frame, Event *)
- {
- X GWindow *win = (GWindow *) xv_get(frame, XV_KEY_DATA, KEY_GWINDOW);
- X delete win;
- X xv_destroy_safe(frame);
- }
- X
- X
- //***************************************************************************
- // void GWAbout::done_proc(Frame frame)
- // PURPOSE:
- // This gets called whenever the about window is destroyed. We need to
- // clean up the associated GWindow structure. Since we want all children
- // to go away as well, we will call this function recursively on our subframes.
- //
- void GWAbout::done_proc(Frame frame)
- {
- X if (!frame)
- X return;
- X GWindow *win = (GWindow *) xv_get(frame, XV_KEY_DATA, KEY_GWINDOW);
- X delete win;
- X xv_destroy_safe(frame);
- }
- X
- X
- //***************************************************************************
- // void GWAbout::panel_events(Xv_window, Event *, Notify_arg, Notify_event_type)
- //
- Notify_value GWAbout::panel_events(Xv_window win, Event *event, Notify_arg arg, Notify_event_type type)
- {
- X current_icon ^= 1;
- X xv_set(icon,
- X PANEL_LABEL_IMAGE, get_gopher(current_icon),
- X NULL);
- X return notify_next_event_func(win, (Notify_event) event, arg, type);
- }
- X
- SHAR_EOF
- chmod 0664 GWAbout.cc ||
- echo 'restore of GWAbout.cc failed'
- Wc_c="`wc -c < 'GWAbout.cc'`"
- test 5530 -eq "$Wc_c" ||
- echo 'GWAbout.cc: original size 5530, current size' "$Wc_c"
- fi
- # ============= GWBinary.cc ==============
- if test -f 'GWBinary.cc' -a X"$1" != X"-c"; then
- echo 'x - skipping GWBinary.cc (File already exists)'
- else
- echo 'x - extracting GWBinary.cc (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'GWBinary.cc' &&
- //
- // GWBinary.cc
- //
- // (c) Copyright 1993, San Diego State University -- College of Sciences
- // (See the COPYRIGHT file for more Copyright information)
- //
- // Implementation of the GWBinary class
- //
- #include "GWBinary.h"
- #include "xvgopher.h"
- #include "cursor.h"
- #include <fcntl.h>
- #include <unistd.h>
- X
- X
- //***************************************************************************
- // GWBinary::GWBinary(Frame par)
- //
- GWBinary::GWBinary(Frame par) : GWDownload(par, GWDownload::BINARY)
- {
- }
- X
- X
- SHAR_EOF
- chmod 0644 GWBinary.cc ||
- echo 'restore of GWBinary.cc failed'
- Wc_c="`wc -c < 'GWBinary.cc'`"
- test 498 -eq "$Wc_c" ||
- echo 'GWBinary.cc: original size 498, current size' "$Wc_c"
- fi
- # ============= GWBookmarks.cc ==============
- if test -f 'GWBookmarks.cc' -a X"$1" != X"-c"; then
- echo 'x - skipping GWBookmarks.cc (File already exists)'
- else
- echo 'x - extracting GWBookmarks.cc (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'GWBookmarks.cc' &&
- //
- // GWBookmarks.cc
- //
- // (c) Copyright 1993, San Diego State University -- College of Sciences
- // (See the COPYRIGHT file for more Copyright information)
- //
- // This file contains the routines of the GWBookmarks class which
- // deal with the opening of windows.
- //
- #include "GWBookmarks.h"
- #include "xvgopher.h"
- #include "cursor.h"
- #include "icons.h"
- #include <fstream.h>
- #include <string.h>
- #include <xview/svrimage.h>
- #include <xview/icon.h>
- #include <xview/defaults.h>
- X
- X
- #define KEY_SAVE_BTN 30010
- #define KEY_SAVE_TXT 30011
- X
- X
- GWBookmarks *bookmarks;
- X
- X
- //***************************************************************************
- // GWBookmarks::GWBookmarks(Frame par)
- //
- GWBookmarks::GWBookmarks(Frame par)
- {
- X parent = par;
- }
- X
- X
- //***************************************************************************
- // GWBookmarks::~GWBookmarks()
- //
- GWBookmarks::~GWBookmarks()
- {
- X write_bookmarks();
- }
- X
- X
- //***************************************************************************
- // int GWBookmarks::open(Response *resp)
- // PURPOSE:
- // This will create a window in which the bookmarks directory will be
- // displayed.
- //
- int GWBookmarks::open(Response *resp)
- {
- X if (GWList::open(resp) != OK)
- X return NOTOK;
- X
- X int left = 8; // Position of leftmost button in window
- X
- X //
- X // Create the save button and save text field.
- X //
- X Panel_item save_btn = (Panel_item) xv_create(panel, PANEL_BUTTON,
- X XV_X, left,
- X XV_Y, 8,
- X PANEL_LABEL_STRING, "Save",
- X PANEL_INACTIVE, TRUE,
- X NULL);
- X Panel_item save_txt = (Panel_item) xv_create(panel, PANEL_TEXT,
- X XV_X, left + 56,
- X XV_Y, 8,
- X PANEL_LABEL_STRING, "Save in:",
- X PANEL_VALUE_DISPLAY_WIDTH, 260,
- X PANEL_INACTIVE, TRUE,
- X NULL);
- X
- X xv_set(dir_list,
- X XV_KEY_DATA, KEY_SAVE_BTN, save_btn,
- X XV_KEY_DATA, KEY_SAVE_TXT, save_txt,
- X NULL);
- X
- X //
- X // Now some things which need to be set for both FRAMEs and
- X // FRAME_CMDs
- X //
- X xv_set(frame,
- X FRAME_SHOW_FOOTER, TRUE,
- X FRAME_RIGHT_FOOTER, "Local bookmarks",
- X FRAME_DONE_PROC, (void (*)(Frame)) done_proc,
- X XV_KEY_DATA, KEY_GWINDOW, this,
- X XV_SHOW, preferences.get_popup_bookmarks(),
- X FRAME_LABEL, "Xvgopher Bookmarks",
- X NULL);
- X
- X modify_list_menu();
- X
- X read_bookmarks();
- X
- X return OK;
- }
- X
- X
- //***************************************************************************
- // void GWBookmarks::read_bookmarks()
- //
- void GWBookmarks::read_bookmarks()
- {
- X char *home = getenv("HOME");
- X if (!home)
- X home = ".";
- X char filename[100];
- X sprintf(filename, "%s/.xvgopher-bm", home);
- X ifstream in(filename);
- X if (in.fail())
- X return;
- X
- X xv_set(dir_list,
- X XV_SHOW, FALSE,
- X NULL);
- X char buffer[10000];
- X int i = 0;
- X while (!in.eof())
- X {
- X in.getline(buffer, 10000);
- X if (in.eof())
- X break;
- X if (i == 0) // First line of the file
- X {
- X //
- X // The first line of the file is supposed to contain the version number.
- X // However, if the file does not contain one, we will just assume that
- X // the file was created with version 1.0
- X //
- X if (strncmp(buffer, "XvGo", 4) == 0)
- X {
- X //
- X // We got a version number!
- X //
- X continue; // There is only one version, so what are we worrying about???
- X }
- X }
- X Response *r = new Response(buffer);
- X xv_set(dir_list,
- X PANEL_LIST_INSERT, i,
- X PANEL_LIST_STRING, i, r->get_title(),
- X PANEL_LIST_GLYPH, i, get_image(r->get_type()),
- X PANEL_LIST_CLIENT_DATA, i, r,
- X NULL);
- X i++;
- X }
- X xv_set(dir_list,
- X XV_SHOW, TRUE,
- X NULL);
- }
- X
- X
- //***************************************************************************
- // void GWBookmarks::write_bookmarks()
- //
- void GWBookmarks::write_bookmarks()
- {
- X char *home = getenv("HOME");
- X if (!home)
- X home = ".";
- X char filename[100];
- X sprintf(filename, "%s/.xvgopher-bm", home);
- X ofstream out(filename);
- X if (out.fail())
- X return;
- X
- X int n = (int) xv_get(dir_list, PANEL_LIST_NROWS);
- X
- X //
- X // First put the version number in the file so that we can determine later on
- X // if the file needs conversion or not.
- X //
- X out << "XvGo " << VERSION << "\n";
- X
- X for (int i = 0; i < n; i++)
- X {
- X Response *r = (Response *) xv_get(dir_list, PANEL_LIST_CLIENT_DATA, i);
- X out << r->get_type() << r->get_title() << "\t" << r->get_command() << "\t" <<
- X r->get_server() << "\t" << r->get_port() << "\n";
- X }
- X out.close();
- }
- X
- X
- //***************************************************************************
- // void GWBookmarks::row_deselect(int row, Response *resp)
- //
- void GWBookmarks::row_deselect(int row, Response *resp)
- {
- X Panel_item save_btn = (Panel_item) xv_get(dir_list, XV_KEY_DATA, KEY_SAVE_BTN);
- X Panel_item save_txt = (Panel_item) xv_get(dir_list, XV_KEY_DATA, KEY_SAVE_TXT);
- X
- X row = row;
- X resp = resp;
- X //
- X // Hide the button and the text item
- X //
- X xv_set(save_btn,
- X PANEL_INACTIVE, TRUE,
- X NULL);
- X xv_set(save_txt,
- X PANEL_INACTIVE, TRUE,
- X NULL);
- X
- X //
- X // The menu of the dir_list has the remove item. This needs to be made inactive.
- X //
- X xv_set(bookmark_mi,
- X MENU_INACTIVE, TRUE,
- X NULL);
- X xv_set(show_info_mi,
- X MENU_INACTIVE, TRUE,
- X NULL);
- }
- X
- X
- //***************************************************************************
- // void GWBookmarks::row_select(int row, Response *resp)
- //
- void GWBookmarks::row_select(int row, Response *resp)
- {
- X Panel_item save_btn = (Panel_item) xv_get(dir_list, XV_KEY_DATA, KEY_SAVE_BTN);
- X Panel_item save_txt = (Panel_item) xv_get(dir_list, XV_KEY_DATA, KEY_SAVE_TXT);
- X
- X row = row;
- X resp = resp;
- X //
- X // Show the button and the text item if the selected item is savable
- X //
- X if (strchr("09", resp->get_type()))
- X {
- X xv_set(save_btn,
- X PANEL_INACTIVE, FALSE,
- X NULL);
- X xv_set(save_txt,
- X PANEL_INACTIVE, FALSE,
- X NULL);
- X }
- X
- X //
- X // The menu of the dir_list has the remove item. This needs to be made active.
- X //
- X xv_set(bookmark_mi,
- X MENU_INACTIVE, FALSE,
- X NULL);
- X xv_set(show_info_mi,
- X MENU_INACTIVE, FALSE,
- X NULL);
- }
- X
- X
- //***************************************************************************
- // void GWBookmarks::show()
- //
- void GWBookmarks::show()
- {
- X xv_set(frame,
- X XV_SHOW, TRUE,
- X NULL);
- }
- X
- X
- //***************************************************************************
- // void GWBookmarks::add(Response *resp)
- // PURPOSE:
- // Add a line to the list of bookmarks.
- //
- void GWBookmarks::add(Response *resp)
- {
- X xv_set(dir_list,
- X XV_SHOW, FALSE,
- X NULL);
- X
- X int n = (int) xv_get(dir_list, PANEL_LIST_NROWS);
- X xv_set(dir_list,
- X PANEL_LIST_INSERT, n,
- X PANEL_LIST_STRING, n, resp->get_title(),
- X PANEL_LIST_GLYPH, n, get_image(resp->get_type()),
- X PANEL_LIST_CLIENT_DATA, n, resp,
- X NULL);
- X
- X xv_set(dir_list,
- X XV_SHOW, TRUE,
- X NULL);
- }
- X
- X
- //***************************************************************************
- // void GWBookmarks::modify_list_menu()
- // Modify the Bookmarks List menu so that if contains the following items:
- // Remove bookmark
- // Show item info
- //
- void GWBookmarks::modify_list_menu()
- {
- X //
- X // We want to modify the scrolling list's menu, so we need to get it,
- X // add the items and then put it back.
- X //
- X Menu m = (Menu) xv_get(dir_list, PANEL_ITEM_MENU);
- X bookmark_mi = (Menu_item) xv_create(NULL, MENUITEM,
- X MENU_STRING, "Remove bookmark",
- X MENU_NOTIFY_PROC, remove_bookmark_proc,
- X MENU_INACTIVE, TRUE,
- X XV_KEY_DATA, KEY_GWINDOW, this,
- X NULL);
- X xv_set(m,
- X MENU_APPEND_ITEM, bookmark_mi,
- X NULL);
- X show_info_mi = (Menu_item) xv_create(NULL, MENUITEM,
- X MENU_STRING, "Show item info",
- X MENU_NOTIFY_PROC, show_item_info_proc,
- X MENU_INACTIVE, FALSE,
- X XV_KEY_DATA, KEY_GWINDOW, this,
- X NULL);
- X xv_set(m,
- X MENU_APPEND_ITEM, show_info_mi,
- X NULL);
- X xv_set(dir_list,
- X PANEL_ITEM_MENU, m,
- X NULL);
- }
- X
- X
- //***************************************************************************
- // void GWBookmarks::remove_bookmark_proc(Menu menu, Menu_item mi)
- //
- void GWBookmarks::remove_bookmark_proc(Menu menu, Menu_item mi)
- {
- X GWBookmarks *gwindow = (GWBookmarks *) xv_get(mi, XV_KEY_DATA, KEY_GWINDOW);
- X
- X //
- X // First make sure that there really is a row selected...
- X //
- X if (!xv_get(gwindow->dir_list, PANEL_LIST_SELECTED, gwindow->current_selected))
- X return;
- X
- X menu = menu;
- X //
- X // Some row was selected and we need to remove the row from the list.
- X //
- X Response *r = (Response *) xv_get(gwindow->dir_list, PANEL_LIST_CLIENT_DATA, gwindow->current_selected);
- X delete r;
- X xv_set(gwindow->dir_list,
- X PANEL_LIST_DELETE, gwindow->current_selected,
- X NULL);
- X xv_set(gwindow->bookmark_mi,
- X MENU_INACTIVE, TRUE,
- X NULL);
- }
- X
- X
- //***************************************************************************
- // void GWBookmarks::done_proc(Frame frame)
- // This gets called whenever a command frame is destroyed. In the case
- // of the book marks window, we only need to hide the window.
- //
- void GWBookmarks::done_proc(Frame frame)
- {
- X xv_set(frame,
- X XV_SHOW, FALSE,
- X NULL);
- }
- X
- X
- //***************************************************************************
- SHAR_EOF
- chmod 0664 GWBookmarks.cc ||
- echo 'restore of GWBookmarks.cc failed'
- Wc_c="`wc -c < 'GWBookmarks.cc'`"
- test 8907 -eq "$Wc_c" ||
- echo 'GWBookmarks.cc: original size 8907, current size' "$Wc_c"
- fi
- # ============= GWDirectory.cc ==============
- if test -f 'GWDirectory.cc' -a X"$1" != X"-c"; then
- echo 'x - skipping GWDirectory.cc (File already exists)'
- else
- echo 'x - extracting GWDirectory.cc (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'GWDirectory.cc' &&
- //
- // GWDirectory.cc
- //
- // (c) Copyright 1993, San Diego State University -- College of Sciences
- // (See the COPYRIGHT file for more Copyright information)
- //
- // This file contains the routines of the GWDirectory class which
- // deal with the opening of windows.
- //
- #include "GWDirectory.h"
- #include "xvgopher.h"
- #include "GWBookmarks.h"
- #include "GWPref.h"
- #include "GWAbout.h"
- #include "GWGopher.h"
- #include <xview/notice.h>
- #include <stream.h>
- #include <string.h>
- X
- X
- #define KEY_SAVE_BTN 30010
- #define KEY_SAVE_TXT 30011
- X
- X
- //***************************************************************************
- // GWDirectory::GWDirectory(Frame par)
- //
- GWDirectory::GWDirectory(Frame par)
- {
- X parent = par;
- }
- X
- X
- //***************************************************************************
- // int GWDirectory::open(Response *resp)
- // PURPOSE:
- // This will create a window in which a gopher directory will be
- // displayed. There is a special case for this window: it can be
- // the first window created for this program. Hence, if the
- // parent is NULL, the window will NOT be a command window but a
- // regular window.
- //
- int GWDirectory::open(Response *resp)
- {
- X //
- X // Let the base class create the window. We will only add the buttons
- X //
- X if (GWList::open(resp) != OK)
- X return NOTOK;
- X
- X int left = 8; // Position of leftmost button in window
- X if (!parent)
- X {
- X //
- X // The main frame gets the Gopher menu button and the Quit
- X // button
- X //
- X Menu menu = (Menu) xv_create(NULL, MENU,
- X MENU_NOTIFY_PROC, menu_proc,
- X MENU_ITEM,
- X MENU_STRING, "Bookmarks...",
- X NULL,
- X MENU_ITEM,
- X MENU_STRING, "Another Gopher...",
- X NULL,
- X MENU_ITEM,
- X MENU_STRING, "",
- X MENU_FEEDBACK, FALSE,
- X NULL,
- X MENU_ITEM,
- X MENU_STRING, "Preferences...",
- X NULL,
- X MENU_ITEM,
- X MENU_STRING, "",
- X MENU_FEEDBACK, FALSE,
- X NULL,
- X MENU_ITEM,
- X MENU_STRING, "About...",
- X NULL,
- X XV_KEY_DATA, KEY_GWINDOW, this,
- X NULL);
- X xv_create(panel, PANEL_BUTTON,
- X XV_X, 8,
- X XV_Y, 8,
- X PANEL_LABEL_STRING, "Gopher",
- X PANEL_ITEM_MENU, menu,
- X NULL);
- X
- X //
- X // Since we still want to put the other buttons in this panel,
- X // we need to make sure they do not overlap. That's why the
- X // variable 'left' has the pixel location of the next button.
- X //
- X left = 92;
- X
- X //
- X // Since we are the parent of all windows, there is only one of us. Therefore,
- X // this is a good place to create the book marks window.
- X // The Response parameter to the open member is really a dummy.
- X //
- X bookmarks = new GWBookmarks(frame);
- X bookmarks->open(resp);
- X
- X //
- X // The same holds true for the preferences window...
- X //
- X gwpref = new GWPref(frame);
- X gwpref->open(resp);
- X }
- X
- #if USE_SAVE
- X //
- X // Create the save button and save text field.
- X //
- X Panel_item save_btn = (Panel_item) xv_create(panel, PANEL_BUTTON,
- X XV_X, left,
- X XV_Y, 8,
- X PANEL_LABEL_STRING, "Save",
- X PANEL_INACTIVE, TRUE,
- X NULL);
- X Panel_item save_txt = (Panel_item) xv_create(panel, PANEL_TEXT,
- X XV_X, left + 56,
- X XV_Y, 8,
- X PANEL_LABEL_STRING, "Save in:",
- X PANEL_VALUE_DISPLAY_WIDTH, 260,
- X PANEL_INACTIVE, TRUE,
- X NULL);
- X
- X xv_set(dir_list,
- X XV_KEY_DATA, KEY_SAVE_BTN, save_btn,
- X XV_KEY_DATA, KEY_SAVE_TXT, save_txt,
- X NULL);
- #endif USE_SAVE
- X
- X //
- X // Now some things which need to be set for both FRAMEs and
- X // FRAME_CMDs
- X //
- X xv_set(frame,
- X XV_SHOW, TRUE,
- X FRAME_RIGHT_FOOTER, info->get_server(),
- X FRAME_DONE_PROC, done_proc,
- X NULL);
- X
- X //
- X // Modify the list menu
- X //
- X modify_list_menu();
- X
- X //
- X // Let the user know that we are working on something...
- X //
- X frame_busy(frame);
- X
- X //
- X // Now we need to build the connection and get information from it
- X //
- X gopher = new Gopher(this);
- X if (gopher->open(info->get_server(), info->get_port()) == NOTOK) // Connection
- X {
- X xv_create(frame, NOTICE,
- X NOTICE_MESSAGE_STRINGS, "Unable to connect to remote gopher",
- X info->get_server(),
- X NULL,
- X NOTICE_BUTTON_YES, "Bummer",
- X NOTICE_BLOCK_THREAD, TRUE,
- X NOTICE_LOCK_SCREEN, TRUE,
- X XV_SHOW, TRUE,
- X NULL);
- X return NOTOK;
- X }
- X gopher->read(info->get_type(), info->get_command()); // Get info
- X
- X return OK;
- }
- X
- X
- //***************************************************************************
- // void GWDirectory::modify_list_menu()
- // Modify the Directory List menu so that if contains the following items:
- // Set bookmark
- // Show item info
- //
- void GWDirectory::modify_list_menu()
- {
- X //
- X // We want to modify the scrolling list's menu, so we need to get it,
- X // add the items and then put it back.
- X //
- X Menu m = (Menu) xv_get(dir_list, PANEL_ITEM_MENU);
- X bookmark_mi = (Menu_item) xv_create(NULL, MENUITEM,
- X MENU_STRING, "Set bookmark",
- X MENU_NOTIFY_PROC, set_bookmark_proc,
- X MENU_INACTIVE, TRUE,
- X XV_KEY_DATA, KEY_GWINDOW, this,
- X NULL);
- X xv_set(m,
- X MENU_APPEND_ITEM, bookmark_mi,
- X NULL);
- X show_info_mi = (Menu_item) xv_create(NULL, MENUITEM,
- X MENU_STRING, "Show item info",
- X MENU_NOTIFY_PROC, show_item_info_proc,
- X MENU_INACTIVE, TRUE,
- X XV_KEY_DATA, KEY_GWINDOW, this,
- X NULL);
- X xv_set(m,
- X MENU_APPEND_ITEM, show_info_mi,
- X NULL);
- X xv_set(dir_list,
- X PANEL_ITEM_MENU, m,
- X NULL);
- }
- X
- X
- //***************************************************************************
- // void GWDirectory::row_deselect(int, Response *)
- //
- void GWDirectory::row_deselect(int, Response *)
- {
- #if USE_SAVE
- X //
- X // Hide the button and the text item
- X //
- X Panel_item save_btn = (Panel_item) xv_get(dir_list, XV_KEY_DATA, KEY_SAVE_BTN);
- X Panel_item save_txt = (Panel_item) xv_get(dir_list, XV_KEY_DATA, KEY_SAVE_TXT);
- X
- X xv_set(save_btn,
- X PANEL_INACTIVE, TRUE,
- X NULL);
- X xv_set(save_txt,
- X PANEL_INACTIVE, TRUE,
- X NULL);
- #endif USE_SAVE
- X if (!parent)
- X {
- X xv_set(bookmark_mi,
- X MENU_INACTIVE, TRUE,
- X NULL);
- X xv_set(show_info_mi,
- X MENU_INACTIVE, TRUE,
- X NULL);
- X }
- }
- X
- X
- //***************************************************************************
- // void GWDirectory::row_select(int, Response *)
- //
- void GWDirectory::row_select(int, Response *)
- {
- #if USE_SAVE
- X //
- X // Show the button and the text item if the selected item is savable
- X //
- X if (strchr("09", resp->get_type()))
- X {
- X Panel_item save_btn = (Panel_item) xv_get(dir_list, XV_KEY_DATA, KEY_SAVE_BTN);
- X Panel_item save_txt = (Panel_item) xv_get(dir_list, XV_KEY_DATA, KEY_SAVE_TXT);
- X
- X xv_set(save_btn,
- X PANEL_INACTIVE, FALSE,
- X NULL);
- X xv_set(save_txt,
- X PANEL_INACTIVE, FALSE,
- X NULL);
- X }
- #endif USE_SAVE
- X xv_set(show_info_mi,
- X MENU_INACTIVE, FALSE,
- X NULL);
- X xv_set(bookmark_mi,
- X MENU_INACTIVE, FALSE,
- X NULL);
- }
- X
- X
- //***************************************************************************
- // void GWDirectory::display()
- //
- void GWDirectory::display()
- {
- X gopher->start_get();
- X int i = 0;
- X char *str;
- X
- X frame_unbusy(frame);
- X xv_set(dir_list,
- X XV_SHOW, FALSE,
- X NULL);
- X while (str = gopher->get_next())
- X {
- X Response *r = new Response(str);
- X xv_set(dir_list,
- X PANEL_LIST_INSERT, i,
- X PANEL_LIST_STRING, i, r->get_title(),
- X PANEL_LIST_GLYPH, i, get_image(r->get_type()),
- X PANEL_LIST_CLIENT_DATA, i, r,
- X NULL);
- X i++;
- X }
- X xv_set(dir_list,
- X XV_SHOW, TRUE,
- X NULL);
- }
- X
- X
- #if USE_SAVE
- //***************************************************************************
- // void GWDirectory::save_notify(Panel_item item, Event *event)
- //
- void GWDirectory::save_notify(Panel_item item, Event *event)
- {
- X event = event;
- X GWDirectory *gwindow = (GWDirectory *) xv_get(item, XV_KEY_DATA, KEY_GWINDOW);
- X Panel_item save_txt = (Panel_item) xv_get(item, XV_KEY_DATA, KEY_SAVE_TXT);
- X
- X char *filename = (char *) xv_get(save_txt, PANEL_VALUE);
- }
- #endif USE_SAVE
- X
- X
- //***************************************************************************
- // void GWDirectory::menu_proc(Menu menu, Menu_item mi)
- //
- void GWDirectory::menu_proc(Menu menu, Menu_item mi)
- {
- X GWDirectory *gwindow = (GWDirectory *) xv_get(menu, XV_KEY_DATA, KEY_GWINDOW);
- X char *item = (char *) xv_get(mi, MENU_STRING);
- X
- X if (strcmp(item, "Bookmarks...") == 0)
- X {
- X bookmarks->show();
- X }
- X else if (strcmp(item, "Preferences...") == 0)
- X {
- X //
- X // Build a preferences window
- X //
- X gwpref->show();
- X }
- X else if (strcmp(item, "About...") == 0)
- X {
- X //
- X // Build an About window
- X //
- X GWAbout *about = new GWAbout(gwindow->frame);
- X about->open(NULL);
- X }
- X else if (strcmp(item, "Another Gopher...") == 0)
- X {
- X //
- X // Get information from the user about where to contact
- X // a new gopher server.
- X //
- X GWGopher *newgopher = new GWGopher(gwindow->frame);
- X newgopher->open(gwindow->info);
- X }
- }
- X
- X
- //***************************************************************************
- // void GWDirectory::set_bookmark_proc(Menu menu, Menu_item mi)
- //
- void GWDirectory::set_bookmark_proc(Menu menu, Menu_item mi)
- {
- X GWDirectory *gwindow = (GWDirectory *) xv_get(mi, XV_KEY_DATA, KEY_GWINDOW);
- X
- X menu = menu;
- X if (gwindow->current_selected == -1)
- X {
- X //
- X // No row is selected. We will assume we want to add a bookmark pointing to the
- X // current directory. This is simple since we already have a Response object
- X // for ourselves.
- X //
- X bookmarks->add(new Response(gwindow->info));
- X }
- X else
- X {
- X //
- X // Some row was selected. This is cool. All we need to do now is retrieve the
- X // data associated with that row and add it to the bookmark list.
- X //
- X Response *r;
- X r = (Response *) xv_get(gwindow->dir_list, PANEL_LIST_CLIENT_DATA, gwindow->current_selected);
- X bookmarks->add(new Response(r));
- X }
- }
- X
- X
- X
- SHAR_EOF
- chmod 0664 GWDirectory.cc ||
- echo 'restore of GWDirectory.cc failed'
- Wc_c="`wc -c < 'GWDirectory.cc'`"
- test 9592 -eq "$Wc_c" ||
- echo 'GWDirectory.cc: original size 9592, current size' "$Wc_c"
- fi
- true || echo 'restore of GWDownload.cc failed'
- echo End of part 1, continue with part 2
- exit 0
-